#ifndef COMMON_H
#define COMMON_H

#include <jansson.h>
#include <curl/curl.h>
#include <uthash.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <sqlite3.h>
#include <microhttpd.h>

// 添加定时器回调函数类型定义
typedef void (*timer_callback_t)(void *arg);

typedef enum {
    EVENT_TIMER_TRIGGER,
    EVENT_API_RESPONSE,
    EVENT_DATA_UPDATE,
    EVENT_DATA_CHECK,
    EVENT_DB_UPDATE,
    EVENT_SCENE_STATUS_CHANGED,
    EVENT_SYSTEM_SHUTDOWN
} event_type_t;

typedef struct {
    event_type_t type;
    void *data;
    size_t data_len;
    char *source;
    void (*cleanup_fn)(void*);
} event_t;

typedef struct {
    char *key;
    json_t *value;
    time_t timestamp;
    UT_hash_handle hh;
} data_item_t;

// 错误码定义
typedef enum {
    SUCCESS = 0,
    ERROR_INVALID_PARAM = -1,
    ERROR_MEMORY_ALLOC = -2,
    ERROR_JSON_PARSE = -3,
    ERROR_API_CALL = -4,
    ERROR_TIMER_CREATE = -5,
    ERROR_THREAD_CREATE = -6,
    ERROR_QUEUE_FULL = -7,
    ERROR_DB_OPERATION = -8,     // 新增数据库错误
    ERROR_DB_NOT_INIT = -9       // 新增数据库未初始化错误
} error_code_t;



#endif
